package behavior.chain2;

public abstract class AbstractLogger implements Logger{

	public static int INFO = 1;
	public static int DEBUG = 2;
	public static int ERROR = 3;

	protected int level;

	// 责任链中的下一个元素
	protected Logger nextLogger;
	
	public AbstractLogger(int level){
		this.level = level;
	}

	public void setNextLogger(Logger nextLogger) {
		this.nextLogger = nextLogger;
	}
	
	public void write(int level, String message) {
		if (this.level <= level) {
			write(message);
		}
		if (nextLogger != null) {
			nextLogger.write(level, message);
		}
	}
	
	abstract protected void write(String message);
}
